version: "0.1"

services:
  # First part.
  # Generate jwt for beacon chain.
  create-jwt:
    container_name: jwt_creator
    image: "docker.io/frapsoft/openssl:latest"
    command: rand -hex 32 | tr -d "\n" > "./jwtsecret/jwt.hex"
    volumes: 
      - ./jwtsecret:/jwtsecret
  
  # Sets up the genesis configuration for the go-ethereum client from a JSON file.
  geth-genesis:
    container_name: geth_initializer
    image: "ethereum/client-go:stable"
    command: --datadir=/execution init /execution/genesis.json
    depends_on:
      create-jwt:
        condition: service_completed_successfully
    volumes:
      - ./execution:/execution
      - ./execution/genesis.json:/execution/genesis.json
  
  geth-account:
    container_name: account
    image: "ethereum/client-go:stable"
    command: account import --datadir=/execution --password=/execution/password.txt /execution/secret.json
    depends_on:
      geth-genesis:
        condition: service_completed_successfully
    volumes:
      - ./execution:/execution

  # Runs the go-ethereum execution client with the specified, unlocked account and necessary
  # APIs to allow for proof-of-stake consensus via Prysm.
  geth:
    container_name: geth
    image: "ethereum/client-go:stable"
    command:
      - --http
      - --http.api=debug,net,eth,web3,txpool,admin
      - --http.addr=0.0.0.0
      - --http.corsdomain=*
      - --ws
      - --ws.api=debug,net,eth,web3,txpool,admin
      - --ws.addr=0.0.0.0
      - --ws.origins=*
      - --authrpc.vhosts=*
      - --authrpc.addr=0.0.0.0
      - --authrpc.jwtsecret=/jwtsecret/jwt.hex
      - --datadir=/execution
      - --allow-insecure-unlock
      - --unlock=0x123463a4b065722e99115d6c222f267d9cabb524
      - --mine
      - --miner.etherbase=0x123463a4b065722e99115d6c222f267d9cabb524
      - --password=/execution/password.txt
      - --nodiscover
      - --syncmode=full
      - --networkid=32382
    ports:
      - 30303:30303
      - 8551:8551
      - 8545:8545
      - 8546:8546
    depends_on:
      geth-genesis:
        condition: service_completed_successfully
      geth-account:
        condition: service_completed_successfully
    volumes:
      - ./execution:/execution
      - ./jwtsecret:/jwtsecret